﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AcademicPlanner.Framework.Helpers;

namespace AcademicPlanner.Presentation
{
	/// <summary>
	/// View(TModel) is the base class for all strongly typed view pages in the AcademicPlanner application.
	/// It encapsulates common view page functionality such as translation of string messages
	/// and setting of default properties.
	/// </summary>
	/// <typeparam name="TModel">The type of the model object of the strongly typed View.</typeparam>
	/// <version>1.0</version>
	/// <since>1.0</since>
	public abstract class View<TModel> : ViewPage<TModel> where TModel : class
    {
		/// <summary>
		/// Format of page title; provides a placeholder for extra text.
		/// </summary>
		protected string titleFormat = "My Academic Planner - {0}";

		/// <summary>
		/// Heading to displayed on the page.
		/// </summary>
		protected string pageHeading = "";


		/// <summary>
		/// Initializes the page. This method is an override and sets the current <code>Culture</code>
		/// of the page to a value read from the session.
		/// </summary>
		/// <param name="e">The event to initialize the page.</param>
		/// <seealso cref="M:AcademicPlanner.Framework.Helpers.SessionHelper.GetUserCulture"/>
		/// <version>1.0</version>
		/// <since>1.0</since>
		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);
			Culture = SessionHelper.GetUserCulture();
		}

		/// <summary>
		/// Translates a string message from the application's source language to its current
		/// target language read from the session. This method is a convenience wrapper of
		/// <see cref="M:AcademicPlanner.Framework.Helpers.TranslationHelper.Translate"/> 
		/// for <code>View</code> objects.
		/// </summary>
		/// <param name="pText">The message to translate.</param>
		/// <returns>The translated message.</returns>
		/// <seealso cref="M:AcademicPlanner.Framework.Helpers.TranslationHelper.Translate"/>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public string Tr(string pText)
		{
			return TranslationHelper.Translate(pText, "Presentation");
		}
    }

}
